#include "ET++.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "Zoomer.h"

#include "Class.h"
#include "Menu.h"
#include "Clipper.h"
#include "MenuBar.h"

//---- Zoomer ------------------------------------------------------------------

NewMetaImpl(Zoomer,Scroller, (T(defaultzoom)));

Zoomer::Zoomer(VObject *v, const Point &extent, float dz) : Scroller(v, extent)
{
	defaultzoom= dz;
}

Menu *Zoomer::MakeMenu(int menuId)
{
	if (menuId == cVIEWMENU) {
		Menu *m= new Menu(cVIEWMENU, "View");
		m->AppendItems(
			"Zoom Out@>",   cZOOMOUT,
			"Zoom In@<",    cZOOMIN,
			"Actual Size",  cZOOMRESET,
			0);
		return m;
	}
	return 0;
}

Clipper *Zoomer::MakeClipper()
{
	Clipper *cl= Scroller::MakeClipper();
	cl->SetZoom(defaultzoom);
	return cl;
}

void Zoomer::DoSetupMenu(Menu *mp)
{
	Scroller::DoSetupMenu(mp);
	if (vf->GetZoom() < 1024)
		mp->EnableItem(cZOOMIN);
	if (vf->GetZoom() > 0.01)
		mp->EnableItem(cZOOMOUT);
	if (vf->GetZoom() != defaultzoom)
		mp->EnableItem(cZOOMRESET);
}

Command *Zoomer::DoMenuCommand(int cmd)
{
	switch (cmd) {
	case cZOOMOUT:
		vf->SetZoom(vf->GetZoom()/1.2);
		break;
	case cZOOMIN:
		vf->SetZoom(vf->GetZoom()*1.2);
		break;
	case cZOOMRESET:
		vf->SetZoom(defaultzoom);
		break;
	default:
		return Scroller::DoMenuCommand(cmd);
	}
	return gNoChanges;
}

